<template>
    <div>
        <h1>职员管理添加</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">姓名</td>
                    <td><input type="text" v-model="info.Name"></td>
                </tr>
                <tr>
                    <td align="right">职员类型</td>
                    <td><select v-model="info.posts">
                            <option value="">请选择</option>
                            <option value="项目经理">项目经理</option>
                            <option value="财务总监">财务总监</option>
                            <option value="普通职员">普通职员</option>

                        </select></td>
                </tr>
                <tr>
                    <td align="right">性别</td>
                    <td><input type="radio" name="str" :value="true" v-model="info.Sex">男
                        <input type="radio" name="str" :value="false" v-model="info.Sex">女
                    </td>
                </tr>
                <tr>
                    <td align="right">身份证号</td>
                    <td><input type="text" v-model="info.Sfzh" maxlength="18"></td>
                </tr>
                <tr>
                    <td align="right">手机号</td>
                    <td><input type="text" v-model="info.Phone" maxlength="11"></td>
                </tr>
                <tr>
                    <td align="right">管理小区</td>
                    <td><textarea v-model="info.Guanli"></textarea></td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td><input type="button" value="添加" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios';
import { useRouter } from 'vue-router';
const rouder = useRouter();
let info: any = reactive({
    "Name": "",
    "posts": "",
    "Sex": '',
    "Sfzh": "",
    "Phone": "",
    "Guanli": ""
})
const ok = () => {
    if (info.Name == "") {
        alert("姓名不能为空");
        return;
    }
    if (info.posts == "") {
        alert("职员类型不能为空");
        return;
    }
    if (info.Sfzh == "") {
        alert("身份证号不能为空");
        return;
    }
    if (info.Phone == "") {
        alert("手机号不能为空");
        return;
    }

    let reh = /^1[3-9]\d{9}$/;
    if (reh.test(info.Phone) == false) {
        alert('手机号不合法')
        return;
    }

    if (info.Guanli == "") {
        alert("管理小区不能为空");
        return;
    }
    axios({
        url: '/api/Wook/Add',
        method: 'post',
        data: info
    })
        .then((res) => {
            console.log(res);
            if (res.data == -1) {
                alert("姓名重复")
            }
            if (res.data > 0) {
                alert("添加成功");
                return;
            }
            else {
                alert("添加失败");
                return;
            }
        })
        .catch((err) => {
            console.log(err);

        })
}
</script>

<style scoped></style>